package com.ruoyi.ylyx.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ylyx.domain.YlyxBaseconfig;
import com.ruoyi.ylyx.service.IYlyxBaseconfigService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 基础设置Controller
 * 
 * @author yuexl
 * @date 2021-02-05
 */
@Controller
@RequestMapping("/ylyx/baseconfig")
public class YlyxBaseconfigController extends BaseController
{
    private String prefix = "ylyx/baseconfig";

    @Autowired
    private IYlyxBaseconfigService ylyxBaseconfigService;

    @RequiresPermissions("ylyx:baseconfig:view")
    @GetMapping()
    public String baseconfig()
    {
        return prefix + "/baseconfig";
    }

    /**
     * 查询基础设置列表
     */
    @RequiresPermissions("ylyx:baseconfig:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YlyxBaseconfig ylyxBaseconfig)
    {
        startPage();
        List<YlyxBaseconfig> list = ylyxBaseconfigService.selectYlyxBaseconfigList(ylyxBaseconfig);
        return getDataTable(list);
    }

    /**
     * 导出基础设置列表
     */
    @RequiresPermissions("ylyx:baseconfig:export")
    @Log(title = "基础设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YlyxBaseconfig ylyxBaseconfig)
    {
        List<YlyxBaseconfig> list = ylyxBaseconfigService.selectYlyxBaseconfigList(ylyxBaseconfig);
        ExcelUtil<YlyxBaseconfig> util = new ExcelUtil<YlyxBaseconfig>(YlyxBaseconfig.class);
        return util.exportExcel(list, "baseconfig");
    }

    /**
     * 新增基础设置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存基础设置
     */
    @RequiresPermissions("ylyx:baseconfig:add")
    @Log(title = "基础设置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YlyxBaseconfig ylyxBaseconfig)
    {
        return toAjax(ylyxBaseconfigService.insertYlyxBaseconfig(ylyxBaseconfig));
    }

    /**
     * 修改基础设置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        YlyxBaseconfig ylyxBaseconfig = ylyxBaseconfigService.selectYlyxBaseconfigById(id);
        mmap.put("ylyxBaseconfig", ylyxBaseconfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存基础设置
     */
    @RequiresPermissions("ylyx:baseconfig:edit")
    @Log(title = "基础设置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YlyxBaseconfig ylyxBaseconfig)
    {
        return toAjax(ylyxBaseconfigService.updateYlyxBaseconfig(ylyxBaseconfig));
    }

    /**
     * 删除基础设置
     */
    @RequiresPermissions("ylyx:baseconfig:remove")
    @Log(title = "基础设置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ylyxBaseconfigService.deleteYlyxBaseconfigByIds(ids));
    }
}
